<?php
class Sjpj_exam_ctl extends Ctl{
    function __construct(){
    }
    function main(array $xxfget) {
        $sid=isset($_SESSION['sid'])?$_SESSION['sid']:false;
        if(!$sid){
            $this->showtov("Sjpj_login_v");
            exit();
        }
        $type=!empty($_POST['type'])?$_POST['type']:false;
        if(!$type){
            $cid=$xxfget['cid'];
            if(!xdb::getInstance()->getvar("select id from temstu_tct where sid=".$sid)){//没有答过题就正常显示
                $ct=xdb::getInstance()->getarray("select tct.id as tctid,tname from temclassteacher as tct,temteacher as t where tct.ttid=t.id and tct.tcid=".$cid." order by tctid desc");
                $this->show("sjpj_exam",compact('showt','ct','sid'));
            }else{
                $ct="error";
                $this->show("sjpj_exam",compact('showt','ct'));
            }
        }elseif($type=="sub"){
            $daan=explode(",",$_POST["daan"]);
            $array=array();
            $array2=array();
            for($i=1;$i<count($daan);$i++){
                $array['sid']=$sid;
                $array['tctid']=explode("_", $daan[$i])[0];
                $array['fenshu']=explode("_", $daan[$i])[1];
                $array['pingjia']=explode("_", $daan[$i])[2];
                $array['beizhu']=explode("_", $daan[$i])[3];
                $array2['sid']=$sid;
                $array2['tctid']=explode("_", $daan[$i])[0];
                xdb::getInstance()->indb("temstu_tct", $array, $array2);
            }
            echo 1;
        }
    }
}